SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO



CREATE PROCEDURE [dbo].[AccountInfoIsExist]
    @Login VARBINARY(MAX) ,
    @Email VARBINARY(MAX) ,
    @ServiceInfoId UNIQUEIDENTIFIER ,
    @Id UNIQUEIDENTIFIER
AS 
    BEGIN
        IF ( @Id = NULL ) 
            BEGIN
                SELECT  COUNT(*)
                FROM    AccountInfo
                WHERE   Login = @Login
                        AND Email = @Email
                        AND ServiceInfoId = @ServiceInfoId
                        AND DELETED = 0
            END
        ELSE 
            BEGIN
                SELECT  COUNT(*)
                FROM    AccountInfo
                WHERE   Login = @Login
                        AND Email = @Email
                        AND ServiceInfoId = @ServiceInfoId
                        AND Id != @Id
                        AND DELETED = 0
            END
    END


GO
